<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="auto">
      <el-form-item label="风险等级" prop="type">
          <el-select v-model="queryParams.type"  placeholder="请选择风险等级">
            <el-option
              v-for="dict in dict.type.risk_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="ruralUserList" @selection-change="handleSelectionChange">
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="用户性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column label="手机号" align="center" prop="phonenumber" />
      <el-table-column label="有效证件类型" align="center" prop="validDocumentsType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.certificate_type" :value="scope.row.validDocumentsType"/>
        </template>
      </el-table-column>
      <el-table-column label="证件号" align="center" prop="validCertificateNumber" />
      <el-table-column label="用户类型" align="center" prop="userType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_type" :value="scope.row.userType"/>
        </template>
      </el-table-column>
      <el-table-column label="现居城市" align="center" prop="currentCity" :formatter="currentCityFormatter"  />
      <el-table-column label="风险类型" align="center" prop="riskLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.risk_level" :value="scope.row.userType"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { riskUserList, listRuralUser, getRuralUser, delRuralUser, addRuralUser, updateRuralUser } from "@/api/rural/ruralUser";
import { regionData, CodeToText, TextToCode } from "element-china-area-data";

export default {
  name: "RuralUser",
  dicts: ['certificate_type','sex','user_type','risk_level'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息表格数据
      ruralUserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        type: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      options: regionData
    };
  },
  created() {
    this.riskUserList()
  },
  methods: {
    currentCityFormatter(row, column){
      if (row.currentCity != undefined){
        return row.currentCity.replaceAll(",","")
      }
      return ;
    },
    riskUserList(){
      riskUserList(this.queryParams).then(response => {
        this.ruralUserList = response.data
        this.loading = false
    })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.riskUserList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
